<template>
  <div>
    <el-dialog :visible="abc" width="400px" :show-close="false">
      <div slot="title">
        <img src="../../image/logo.png">
        登陆
      </div>
      <el-form label-position="left" label-width="60px">
        <el-form-item ref="form" label="用户名">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password" type="password"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="primary" @click="getusers()">登录</el-button>
        <el-button type="info" @click="zhuce()">立即注册</el-button>    
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        username: "",
        password: ""
      },
      abc:true,
    };
  },
  created() {
    this.islogin();
  },
  methods: {
    islogin() {
      this.axios.get("/users/islogin").then(ret => {
        let { data, error } = ret.data;
        if (data == 1) {
          this.$router.push("/home");
        }
      });
    },
    zhuce(){
      this.abc=false;
      this.$router.push({name:'regist'});
    },
    getusers() {
      this.axios
        .post("/users/login", { ...this.form })
        .then(ret => {
          const { data } = ret.data;
          this.store.set("userInfo", data);
          this.$router.push({
            name: "home"
          });
        })
        .catch(() => {
          this.$message.error("用户名或密码错误");
        });
    }
  }
};
</script>
<style scoped>
.el-form {
  padding: 0 20px;
}
.zc{
  text-decoration:none;
  color:#fff;
}
</style>
